package com.ht.base.system.biz.convert;

import com.ht.base.system.common.pojo.bo.SysUserRoleBO;
import com.ht.base.system.dao.domain.SysUserRoleDO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类SysUserRoleBeanUtil.java的实现描述：用户和角色关联表工具类
 * 
 * @Author hdx
 * @Date 2023年04月28日
 */
public class SysUserRoleBeanUtil {

    private SysUserRoleBeanUtil(){
    }

    public static SysUserRoleDO sysUserRoleBOToDO(SysUserRoleBO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysUserRoleDO targetObj = new SysUserRoleDO();
        targetObj.setId(srcObj.getSysUserRoleId());//id
        targetObj.setSysUserId(srcObj.getSysUserId());//用户ID
        targetObj.setSysRoleId(srcObj.getSysRoleId());//角色ID
        targetObj.setUpdateTime(srcObj.getUpdateTime());

        return targetObj;
    }

    public static SysUserRoleBO sysUserRoleDOToBO(SysUserRoleDO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysUserRoleBO targetObj = new SysUserRoleBO();
        targetObj.setSysUserRoleId(srcObj.getId());//id
        targetObj.setSysUserId(srcObj.getSysUserId());//用户ID
        targetObj.setSysRoleId(srcObj.getSysRoleId());//角色ID
        targetObj.setUpdateTime(srcObj.getUpdateTime());

        return targetObj;
    }

    public static List<SysUserRoleBO> doList2BOList(List<SysUserRoleDO> doList) {
        List<SysUserRoleBO> boList = new ArrayList<>();
        if (CollectionUtils.isEmpty(doList)) return boList;

        doList.stream().forEach(d -> boList.add(SysUserRoleBeanUtil.sysUserRoleDOToBO(d)));
        return boList;
    }

    public static List<SysUserRoleDO> boList2DOList(List<SysUserRoleBO> boList) {
        List<SysUserRoleDO> doList = new ArrayList<>();
        if (CollectionUtils.isEmpty(boList)) return doList;

        boList.stream().forEach(b -> doList.add(SysUserRoleBeanUtil.sysUserRoleBOToDO(b)));
        return doList;
    }
}